﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GMaps
{
    public class GPolyline:GElement
    {
        public GPolyline()
        {
            Path = new List<GLatLng>();
        }
        public GPolyline(string id)
        {
            Path = new List<GLatLng>();
            ID = id;
        }

        
        public List<GLatLng> Path { get; set; }
        public string StrokeColor { get; set; }

        public string Render(GMap map)
        {
            if (Path.Count != 0)
            {
                string coordinates ="var "+ ID + "Coordinates=[";
                foreach (var item in Path)
                {
                    coordinates += "new " + item.Render() + ",";
                }
                coordinates = coordinates.Substring(0,coordinates.Length-1)+ "];";
                
                string script = coordinates; 
                script += "var " + ID + " = new google.maps.Polyline({";
                script += "path: " + ID + "Coordinates,      strokeColor: \"#FF0000\",      strokeOpacity: 1.0,      strokeWeight: 2";
                script += "});";
                script += ID  + ".setMap(" + map.ID + ");";

                return script;
            }
            return "";
           
        }
    }
}